package com.safety51.bi.config;

import com.safety51.bi.service.ChartConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class ConfigurationChecker implements CommandLineRunner {
    
    private static final Logger log = LoggerFactory.getLogger(ConfigurationChecker.class);
    
    private final ChartConfigService chartConfigService;
    
    // 必需的图表配置
    private static final List<String> REQUIRED_CONFIGS = Arrays.asList(
        "total_sales", "user_count", "order_count", "conversion_rate",
        "sales_trend", "product_distribution", "regional_sales", "sales_table"
    );
    
    public ConfigurationChecker(ChartConfigService chartConfigService) {
        this.chartConfigService = chartConfigService;
    }
    
    @Override
    public void run(String... args) throws Exception {
        log.info("检查必需的图表配置...");
        
        for (String chartId : REQUIRED_CONFIGS) {
            if (chartConfigService.getConfigByChartId(chartId) == null) {
                log.warn("缺失图表配置: {}", chartId);
            } else {
                log.info("图表配置存在: {}", chartId);
            }
        }
        
        log.info("图表配置检查完成");
    }
}